using System;
using System.Collections;
using DG.Tweening;
using UnityEngine;
using Voodoo.Pattern;

public class GamifiedRVView : MonoBehaviour
{
	public RectTransform Cursor;

	private Sequence sequence;

	public Action<int> OnClicked;

	public int GetValue()
	{
		float x = Cursor.anchoredPosition.x;
		if (x < -160f)
		{
			return 1;
		}
		if (x < -60f)
		{
			return 2;
		}
		if (x < 60f)
		{
			return 5;
		}
		if (x < 160f)
		{
			return 2;
		}
		return 1;
	}

	private void Start()
	{
	}

	private IEnumerator MoveCursor()
	{
		int direction = 1;
		while (true)
		{
			yield return Cursor.DOAnchorPosX(220f * (float)direction, 1f, snapping: true).WaitForCompletion();
			direction *= -1;
		}
	}

	private void OnEnable()
	{
		sequence = DOTween.Sequence();
		StartCoroutine(MoveCursor());
	}

	public void OnRvClick()
	{
		sequence.Kill();
		StopCoroutine(MoveCursor());
		Cursor.DOKill();
		if (SingletonMB<GameManager>.Instance.BetterNoAds)
		{
			OnClicked?.Invoke(GetValue());
		}
		else
		{
			OnClicked?.Invoke(GetValue());
		}
	}

	public void OnNoThanks()
	{
		OnClicked?.Invoke(1);
	}

	private void Update()
	{
	}
}
